package org.hk.kg.finance.stutype.action;


import java.util.List;
import java.util.Map;

import org.hk.kg.TraceObject;
import org.hk.kg.db.DBServiceProxy;
import org.hk.kg.finance.FinanceConstants;
import org.hk.kg.finance.stutype.service.IStuTypeService;
import org.hk.kg.finance.stutype.service.StuTypeService;
import org.hk.kg.ui.KGUiContext;
import org.hk.kg.ui.ParamsStack;
import org.hk.kg.utils.Constants;
import org.hk.kg.web.BaseAction;

public class StuTypeAction extends BaseAction {
	private IStuTypeService stuTypeServ = DBServiceProxy.getProxyClz(StuTypeService.class);
	
	/**
	 * 获取所有的生源组显示
	 * @return
	 */
	public String getStuTypes()
	{   
		List<Map> rlt = stuTypeServ.queryStuTypes();
		StringBuffer buffer = new StringBuffer();
		for(Map m : rlt)
		{
			buffer.append("<tr>")
				.append("<td><input type=\"checkbox\" name=\"stuTypeIds\" value=\"" + m.get("typeId") + "\"/></td>")
				.append("<td>").append(m.get("typeName")).append("</td>")
				.append("<td>").append(m.get("typeDesc")).append("</td>")
				.append("<td>").append(m.get("author")).append("</td>")
				.append("</tr>");
		}
		return buffer.toString();
	}
	
	/**
	 * 创建新的生源组
	 * @param params
	 * @return
	 */
	public String newStuType(ParamsStack params)
	{
		return "new_stu_type";
	}
	
	/**
	 * 删除生源组
	 * @param pamras
	 * @return
	 */
	public String delStuType(ParamsStack pamras)
	{
		Object delIds[] = pamras.getValues("stuTypeIds");
		if(delIds.length == 0)
		{
			KGUiContext.instance.error(Constants.COMMON_FAIL_WINDOW_TITLE,
					FinanceConstants.MSG_STUTYPE_LEAST_ONE);
			return None;
		}
		boolean rlt = stuTypeServ.deleteStuTypes(delIds);
		if(rlt)
		{
			return "stu_type_page";
		}
		else
		{
			return Constants.COMMON_FAIL_ACTION;
		}
	}
	
	public TraceObject modifyStuType(ParamsStack params)
	{
		Object delIds[] = params.getValues("stuTypeIds");
		if(delIds.length != 1)
		{
			KGUiContext.instance.error(Constants.COMMON_FAIL_WINDOW_TITLE,
					FinanceConstants.MSG_STUTYPE_ONLY_ONE);
			return new TraceObject(None);
		}
		TraceObject trace = new TraceObject("modify_stu_type",true);
		trace.setParams(stuTypeServ.getStuTypeById(Integer.valueOf(delIds[0].toString())));
		return trace;
	}

}
